package com.kova.api.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data  //注在类上，提供类的get、set、equals、hashCode、canEqual、toString方法
@Builder
@AllArgsConstructor //注在类上，提供类的全参构造
@NoArgsConstructor  //注在类上，提供类的无参构造
public class Result {

	private int code;
	private String msg;
	private Object data;

	public Result(ResultEnum rsEnum) {
		super();
		this.code = rsEnum.getCode();
		this.msg = rsEnum.getMsg();
	}

	public static Result ok(){
		return new Result(ResultEnum.SUCCESS);
	}
	public static Result ok(Object data){ return Result.builder().code(ResultEnum.SUCCESS.getCode()).msg(ResultEnum.SUCCESS.getMsg()).data(data).build(); }
	public static Result failed(){
		return new Result(ResultEnum.FAILED);
	}
	public static Result failed(String errorMsg){ return Result.builder().code(ResultEnum.FAILED.getCode()).msg(errorMsg).build(); }
	public static Result failed(ResultEnum rsEnum){
		return new Result(rsEnum);
	}
	public static Result failed(int code, String errorMsg){ return Result.builder().code(code).msg(errorMsg).build(); }
	
}
